Skip to content

Conversation

sahas3
Copy link
Member

@sahas3 sahas3 commented Jul 1, 2025

Fixes #3885 by repeating the single int to match with expected spatial dims.

Comment on lines +5634 to +5670
if constexpr (std::is_same<AtenPoolOpT, AtenMaxPool2dOp>() ||
std::is_same<AtenPoolOpT, AtenMaxPool3dOp>()) {
if (!matchPattern(op.getDilation(),
m_TorchListOfConstantInts(dilationInts)))
return rewriter.notifyMatchFailure(
op, "Non-const dilation for pooling op unsupported");

if (kernelSizeInts.size() != 1 && paddingInts.size() != 1 &&
strideInts.size() != 1 && dilationInts.size() != 1) {
return rewriter.notifyMatchFailure(
op,
"Expected one of kernel/stride/padding/dilation to be singleton.");
}

expand(dilationInts, numSpatialDims);

} else if (kernelSizeInts.size() != 1 && paddingInts.size() != 1 &&
strideInts.size() != 1) {
return rewriter.notifyMatchFailure(
op, "Expected one of kernel/stride/padding to be singleton.");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, you can also do:

bool isMaxPool = false;
if constexpr(....) {
    // const dilation check
    isMaxPool = true;
}

// Singleton check for dilation based on the maxpool flag.
// Singleton check for rest of the values.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the singleton check for dilation cannot be decoupled from the singleton check for the other values for MaxPool op. For MaxPool as long as one of the params of kernel/stride/padding/dilation is singleton we can canonicalize it. For AvgPool similarly we have to check for either of kernel/stride/padding to be non-singleton.

So the code will look like:

bool isMaxPool = false;
if constexpr(....) { 
    // const dilation check 
    isMaxPool = true; 
}

if (isMaxPool) {
    // check for one of kernel/stride/padding/dilation to be singleton
} else {
   // one of kernel/stride/padding to be singleton
}

if (isMaxPool) {
    expandDilation
} 

// expand other params

Is that your suggestion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vivekkhandelwal1 can you please clarify if I understood your suggestion as captured in my previous comment? If yes, is it to make the code easier to read?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vivekkhandelwal1 any further thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assertion when lowering from Torch IR for AvgPool2d when kernel is a tuple of a single int
4 participants